/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is Forte for Java, Community Edition. The Initial * Developer of the Original Code is Sun Microsystems, Inc. Portions * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.web.core.jswdk; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import org.openide.DialogDescriptor; import org.openide.TopManager; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; /** * * @author Ian Formanek, Petr Jiricka */ class MapPanel extends javax.swing.JPanel { private String editLabel = NbBundle.getBundle(MapPanel.class).getString("CTL_EditLabel"); private String editFirstString = NbBundle.getBundle(MapPanel.class).getString("CTL_PropertyLabel"); private String editSecondString = NbBundle.getBundle(MapPanel.class).getString("CTL_ValueLabel"); static final long serialVersionUID =2200126933982149348L; /** Creates new form KeyBindingsPanel */ public MapPanel() { initComponents (); HelpCtx.setHelpIDString (this, MapPanel.class.getName ()); } public void setEditLabel(String editLabel) { this.editLabel = editLabel; } public void setEditFirstString(String editFirstString) { this.editFirstString = editFirstString; } public void setEditSecondString(String editSecondString) { this.editSecondString = editSecondString; } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the FormEditor. */ private void initComponents () {//GEN-BEGIN:initComponents listScrollPane = new javax.swing.JScrollPane (); itemsList = new javax.swing.JList (); buttonsPanel = new javax.swing.JPanel (); addButton = new javax.swing.JButton (); editButton = new javax.swing.JButton (); removeButton = new javax.swing.JButton (); paddingPanel = new javax.swing.JPanel (); setLayout (new java.awt.BorderLayout ()); itemsList.addListSelectionListener (new javax.swing.event.ListSelectionListener () { public void valueChanged (javax.swing.event.ListSelectionEvent evt) { itemsListValueChanged (evt); } } ); listScrollPane.setViewportView (itemsList); add (listScrollPane, java.awt.BorderLayout.CENTER); buttonsPanel.setLayout (new java.awt.GridBagLayout ()); java.awt.GridBagConstraints gridBagConstraints1; addButton.setText (org.openide.util.NbBundle.getBundle(MapPanel.class).getString("MapPanel.addButton.text")); addButton.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { addPressed (evt); } } ); gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.gridwidth = 0; gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints1.insets = new java.awt.Insets (0, 0, 5, 0); gridBagConstraints1.weightx = 1.0; buttonsPanel.add (addButton, gridBagConstraints1); editButton.setText (org.openide.util.NbBundle.getBundle(MapPanel.class).getString("MapPanel.editButton.text")); editButton.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { editPressed (evt); } } ); gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.gridwidth = 0; gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints1.insets = new java.awt.Insets (0, 0, 5, 0); gridBagConstraints1.weightx = 1.0; buttonsPanel.add (editButton, gridBagConstraints1); removeButton.setText (org.openide.util.NbBundle.getBundle(MapPanel.class).getString("MapPanel.removeButton.text")); removeButton.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { removePressed (evt); } } ); gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.gridwidth = 0; gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints1.weightx = 1.0; buttonsPanel.add (removeButton, gridBagConstraints1); gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints1.weightx = 1.0; gridBagConstraints1.weighty = 1.0; buttonsPanel.add (paddingPanel, gridBagConstraints1); add (buttonsPanel, java.awt.BorderLayout.EAST); }//GEN-END:initComponents private void removePressed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removePressed // Add your handling code here: int index = itemsList.getSelectedIndex(); if (index < 0) { return; } String txt = (String) itemsList.getSelectedValue(); if (txt == null) { return; } String[] rem = new String[txts.length - 1]; System.arraycopy(txts, 0, rem, 0, index); System.arraycopy(txts, index + 1, rem, index, txts.length - index - 1); txts = rem; itemsList.setListData(txts); propEditor.removeInternal(txt); }//GEN-LAST:event_removePressed private void editPressed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editPressed // Add your handling code here: String txt = (String) itemsList.getSelectedValue(); if (txt == null) { return; } int space = txt.indexOf(' '); txt = txt.substring(space + 1); displayEdit(txt, itemsList.getSelectedIndex()); }//GEN-LAST:event_editPressed private void addPressed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addPressed // Add your handling code here: displayEdit("", -1); // NOI18N }//GEN-LAST:event_addPressed private void itemsListValueChanged (javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_itemsListValueChanged updateButtons (); }//GEN-LAST:event_itemsListValueChanged /** Updates enabled state of buttons */ private void updateButtons () { editButton.setEnabled (itemsList.getSelectedIndices ().length == 1); removeButton.setEnabled (itemsList.getSelectedIndices ().length >= 1); } void setPropertyEditor(PairPropertyEditor propEditor) { this.propEditor = propEditor; txts = propEditor.getTexts(); itemsList.setListData(txts); } void displayEdit(String prefil, final int idx) { final java.awt.Dialog[] dial = new java.awt.Dialog[1]; final MapEditPanel mePanel = new MapEditPanel(editFirstString, editSecondString); mePanel.setTexts(createPrefil(prefil), idx); DialogDescriptor dd = new DialogDescriptor( mePanel, editLabel, true, DialogDescriptor.OK_CANCEL_OPTION, DialogDescriptor.OK_OPTION, new ActionListener() { public void actionPerformed(ActionEvent ev) { if (ev.getSource() == DialogDescriptor.OK_OPTION) { String[] ts = mePanel.getTexts(); String lep = ts[0] + " " + ts[1]; // NOI18N if (idx == -1) { propEditor.addInternal(lep); String[] nval = new String[txts.length + 1]; System.arraycopy(txts, 0, nval, 0, txts.length); nval[txts.length] = lep; txts = nval; } else { propEditor.changeInternal(idx, ts); txts[idx] = lep; } itemsList.setListData(txts); dial[0].setVisible(false); dial[0].dispose(); } else if (ev.getSource() == DialogDescriptor.CANCEL_OPTION) { dial[0].setVisible(false); dial[0].dispose(); } } } ); dial[0] = TopManager.getDefault().createDialog(dd); dial[0].show(); } String[][] createPrefil(String txt) { String[][] ret = new String[2][]; ret[0] = parseTxt(); ret[1] = new String[] {txt}; return ret; } String[] parseTxt() { String[] ret = new String[txts.length]; for (int i = 0; i < ret.length; i++) { int space = txts[i].indexOf(' '); String s = txts[i].substring(0, space); ret[i] = s; } return ret; } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JScrollPane listScrollPane; private javax.swing.JList itemsList; private javax.swing.JPanel buttonsPanel; private javax.swing.JButton addButton; private javax.swing.JButton editButton; private javax.swing.JButton removeButton; private javax.swing.JPanel paddingPanel; // End of variables declaration//GEN-END:variables // my proped PairPropertyEditor propEditor; // strings assigned String txts[]; } /* * Log * 4 Gandalf 1.3 1/13/00 Petr Jiricka More i18n * 3 Gandalf 1.2 11/27/99 Patrik Knakal * 2 Gandalf 1.1 10/23/99 Ian Formanek NO SEMANTIC CHANGE - Sun * Microsystems Copyright in File Comment * 1 Gandalf 1.0 10/7/99 Petr Jiricka * $ */